package org.thirdHero.core.util;

import org.thirdHero.core.constant.CommonConstant;

import java.math.BigDecimal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NumberUtils {
    public static void main(String[] args) {
        System.out.println( isInteger("0"));
    }
    public static boolean isInteger(String str){
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if( !isNum.matches() ){
            return false;
        }
        return true;
    }
    public static boolean isIntegerNotZero(String str){
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if( !isNum.matches() && Integer.parseInt(str)!=0){
            return false;
        }
        return true;
    }
    public static boolean isNumber(String str){
        Pattern pattern = Pattern.compile("-?[0-9]+.?[0-9]+");
        Matcher isNum = pattern.matcher(str);
        if( !isNum.matches() ){
            return false;
        }
        return true;
    }

    /**
     * 是否为整数
     * @param number
     * @return
     */
    public static boolean isIntegerNumber(BigDecimal number){
        if (!"".equals(number) && number != null){
            if (new BigDecimal(number.intValue()).compareTo(number)==0){
                //整数
                return true;
            }else {
                //小数
                return false;
            }
        }
        return false;
    }
    public static boolean isZero(Integer number){
        return (number != null && CommonConstant.ZERO == number) ;
    }
}
